//
//  EmoticonViewModel.swift
//  FaceKeyBoard
//
//  Created by cmh on 15/9/13.
//  Copyright © 2015年 cmh. All rights reserved.
//

import UIKit

class EmoticonViewModel: NSObject {
    
    // 表情包数组
    lazy var packages = [EmoticonPackge]()
    
    // 加载表情
    func loadPackages() {
    
        // 添加最近分组
        packages.append(EmoticonPackge(dict: ["group_name_cn" : "最近"]))
        
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")
        
        let dict = NSDictionary(contentsOfFile: path!)
        
        let array = dict!["packages"] as! [[String: AnyObject]]
        
        for infoDict in array {
            
            let id = infoDict["id"] as! String

            let packagePath = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: "Emoticons.bundle/" + id)
            
            
            let packageDict = NSDictionary(contentsOfFile: packagePath!) as! [String: AnyObject]
            
            // 字典转模型
            packages.append(EmoticonPackge(dict: packageDict))
        
        }
    
//        print(packages)
    }
    
    // 添加表情
    func appendEmoticon(indexpath: NSIndexPath) -> Emoticon {
        
        return packages[indexpath.section].emoticons[indexpath.item]
    
    }

}
